home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / UNDO.PY < prev    next >
Encoding:
Python Source  |  2000-06-20  |  7.1 KB  |  194 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. __doc__='''short description
  65.  
  66. $Id: Undo.py,v 1.21.4.1 2000/06/20 19:28:39 brian Exp $'''
  67. __version__='$Revision: 1.21.4.1 $'[11:-2]
  68.  
  69. import Globals, ExtensionClass
  70. from DateTime import DateTime
  71. from string import atof, find, atoi, split, rfind, join
  72. from AccessControl import getSecurityManager
  73.  
  74. class UndoSupport(ExtensionClass.Base):
  75.  
  76.     __ac_permissions__=(
  77.         ('Undo changes', (
  78.             'manage_undo_transactions', 'undoable_transactions',
  79.             'manage_UndoForm',
  80.             )),
  81.         )
  82.  
  83.     manage_options=(
  84.         {'label':'Undo', 'action':'manage_UndoForm',
  85.          'help':('OFSP','Undo.stx')},
  86.         )
  87.  
  88.     manage_UndoForm=Globals.HTMLFile(
  89.         'undo', globals(),
  90.         PrincipiaUndoBatchSize=20,
  91.         first_transaction=0, last_transaction=20)
  92.  
  93.     def get_request_var_or_attr(self, name, default):
  94.         if hasattr(self, 'REQUEST'):
  95.             REQUEST=self.REQUEST
  96.             if REQUEST.has_key(name): return REQUEST[name]
  97.             if hasattr(self, name): v=getattr(self, name)
  98.             else: v=default
  99.             REQUEST[name]=v
  100.             return v
  101.         else:
  102.             if hasattr(self, name): v=getattr(self, name)
  103.             else: v=default
  104.             return v
  105.  
  106.     def undoable_transactions(self, first_transaction=None,
  107.                               last_transaction=None,
  108.                               PrincipiaUndoBatchSize=None):
  109.  
  110.         if first_transaction is None:
  111.             first_transaction=self.get_request_var_or_attr(
  112.                 'first_transaction', 0)
  113.  
  114.         if PrincipiaUndoBatchSize is None:
  115.             PrincipiaUndoBatchSize=self.get_request_var_or_attr(
  116.                 'PrincipiaUndoBatchSize', 20)
  117.  
  118.         if last_transaction is None:
  119.             last_transaction=self.get_request_var_or_attr(
  120.                 'last_transaction',
  121.                 first_transaction+PrincipiaUndoBatchSize)
  122.  
  123.         spec={}
  124.         
  125.         # A user is allowed to undo transactions that were initiated
  126.         # by any member of a user folder in the place where the user
  127.         # is defined.        
  128.         user = getSecurityManager().getUser()
  129.         if hasattr(user, 'aq_parent'):
  130.             path = join(user.aq_parent.getPhysicalPath()[1:-1], '/')
  131.         else:
  132.             path=''
  133.         if path: spec['user_name']=Prefix(path)
  134.  
  135.         # We also only want to undo things done here
  136.         opath=join(self.getPhysicalPath(),'/')
  137.         if opath: spec['description']=Prefix(opath)
  138.  
  139.         r=Globals.UndoManager.undoInfo(
  140.             first_transaction, last_transaction, spec)
  141.  
  142.         for d in r: d['time']=DateTime(d['time'])
  143.  
  144.         return r
  145.     
  146.     def manage_undo_transactions(self, transaction_info, REQUEST=None):
  147.         """
  148.         """
  149.         undo=Globals.UndoManager.undo
  150.         for i in transaction_info: undo(i)
  151.             
  152.             
  153.         if REQUEST is None: return
  154.         REQUEST['RESPONSE'].redirect("%s/manage_main" % REQUEST['URL1'])
  155.         return ''
  156.                  
  157. Globals.default__class_init__(UndoSupport)
  158.  
  159.  
  160. class Prefix:
  161.     
  162.     __no_side_effects__=1
  163.  
  164.     def __init__(self, path):
  165.         self.value = len(path), path
  166.         
  167.     def __cmp__(self, o):
  168.         l,v = self.value
  169.         rval = cmp(o[:l],v)
  170.         return rval
  171.             
  172.  
  173.